var interfaceApp = function(){
	var shzt = {};
	shzt.kd = Constants.SHFS.SHFS_KD;
	shzt.zxps = Constants.SHFS.SHFS_ZXPS;
	function getAjaxDta(fn,url) {	
		$.ajax({
			type : "get",
			url : Constants.csUrlPath + url ,
			success : function(data) {
				fn.call("", data);
			}
		});
	}
	var xbgzCommon = {
		getJfmxList:function(zh,getWddh){//获币积分列表
			if(getWddh == 1){
				$('.wdxb-cnt-list').addClass('none');
				$('#dhjl').removeClass('none');
				xbgzCommon.getWddh.call(this);
				return;
			}
			var url = 'wdjf/getWdjfmxGroupByRq?zh='+zh;
			getAjaxDta(function(data){
				var ractive = new Ractive({
					el : '#xbgzContainer',
					template : "#xbgz-template",
					oncomplete : function() {
						// 设置收货地址数据	
						ractive.set("xbgzList", data);
					}
				});
			},url);
		},
		getSyjf:function(zh){//获取剩余积分
			var url = 'wdjf/getJfxx?yhlx=0&zh='+zh;
			getAjaxDta(function(data){
				if(data&&data.object){
					$('.xbTotal').text(data.object.jfye);	
				}
			},url)
		},
		getWddh:function(){//获取我的兑换数据
			var wddhUrl = Constants.csUrlPath + 'lpdh/getWddhPagination';
			var ywy  = manager.findParamFromUrl('ywy') ? manager.findParamFromUrl('ywy'):'000000';//业务域（先写死）
			//smart插件使用
//		     myPage = new SmartPage({
//                 node:$("#wd-pager"),
//                 url: wddhUrl,
//                 data:postData,
//                 count : 10,
//                 callback : showList,
//                 type : 'post',
//                 langPath : '../../../common/components/'
//             });
			showList(1,1);
			//加载我的兑换数据 ，flag为1表示初次加载
		     function showList(flag,currPage){
		    	var postData = {
							'currPage':currPage,
							"pageSize":5,
							"ywy":ywy
					};
	    		$.ajax({
	    			type : "post",
	    			data:JSON.stringify(postData),
	    			dateType : "json",
	    			contentType : 'application/json;charset=UTF-8',
	    			url : wddhUrl,
	    			success : function(data) {
	    				var ractive = new Ractive({
	    					el : '#dhjl',
	    					template : "#wddh-template",
	    					data : {
	    						shzt: shzt
	    					},
	    					oncomplete : function() {
	    	    				if(data&&data.data){
	    					    	 ractive.set("wddhList", data.data);
	    					    	 ractive.set('imgUrl',Constants.imgUrl);
	    					    	 if(flag ==1){
	    					    		 currPage = 1;
	    					    	 }
	    					    	 else{
	    					    		 currPage = currPage;
	    					    	 }
	    					    	 var totalPage = Math.ceil(data.total/5);
	    								 $("#wd-pager").createPage({
	    								        pageCount:totalPage,
	    								        current:currPage,
	    								        backFn:function(currPage){
	    								        	showList(0,currPage);
	    								        }
	    								    });	    					
	    		    				}
	    					}
	    				});
	    			}
	    		});
		     }
			
		}
		
	};
	//tab切换
    $('.wdxb-cnt-tab>li').on('click',function(){
    	$('.wdxb-cnt-tab>li').removeClass('active');
    	$(this).addClass('active');
    	var targetId  = $(this).attr('data-id');
    	var currParam = parseInt($(this).attr('data-param'),4);
    	switch(currParam){
    	  case 0:xbgzCommon.getJfmxList(zh);//0表示积分规则
    	       break;
    	  case 1:xbgzCommon.getWddh();
    		  break;//1表示我的兑换
    	  default:break;
    	}
    	$('.wdxb-cnt-list').addClass('none');
    	$('#'+targetId).removeClass('none');
    })
    var zh = '5000000884';
	//页面初始化
	function loadXbgz(){
		var lpid = manager.findParamFromUrl('curTab');//从兑换页过来的参数
		var tabFlag = 0;
		if(lpid && lpid == 1){
			$('.wdxb-cnt-tab>li').removeClass('active');
			$('#dhjlTab').addClass('active');
			tabFlag = 1;
		}
		manager.getYhxx(function(data){//获取账号信息
			if(data&&data.zh){
				zh = data.zh;
			}
			xbgzCommon.getJfmxList(zh,tabFlag);
			xbgzCommon.getSyjf(zh);
		})
	}
	   //物流跟踪
    function wlgz(dhid){
		var wlgzDialog = {
    			url: "../wlgz/wlgz.html?dhid="+dhid,
    			title: 'Logistics tracking',
    			width: "630",
    			height: "400",
    			successCallBackFun: function(){
    				wdDialogClosed("dialog");
    			}
    		}
    		var wlgzWin = dialog(wlgzDialog);
    }
	return {
		init: function(){
			loadXbgz();
		},
		wlgz : function(dhid) {
			wlgz(dhid);
		},
		block: function(msg) {
			$.blockUI({
                message: '<div style="font-size: 14px;font-weight: bold;color: #f60;height: 40px;width: 250px;line-height: 40px;text-align: center;margin: 0 auto;"><img alt="" src="../../img/loading.gif"></div>',
                css: {
                    border: 'none',
                    padding: '2px',
                    top: "50%",
                    left: "40%",
                    backgroundColor: 'none'
                },
                overlayCSS: {
                    backgroundColor: '#333',
                    opacity: 0.3,
                    cursor:'default'
                }
            });
        },
        unblock: function() {
        	$.unblockUI();
        }
	}
}();
$(document).ready(interfaceApp.init);